<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta content="telephone=no" name="format-detection" />
    <!-- 留作将来统一添加 -->
    <TEMPLATE>${TEMPLATE}</TEMPLATE>
    <title>模板html</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css">
    <link rel="stylesheet" type="text/css" href="../../css/data-flex.min.css">
    <style type="text/css">
        body {
            padding-top: 50px;
        }

        .navs {
            z-index: 999;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            height: 50px;
            background: rgba(90, 194, 255, 1);
        }

        .nav {
            font-size: 15px;
            font-weight: 500;
            color: rgba(255, 255, 255, 0.8);
        }

        .active {
            position: relative;
            font-size: 16px;
            font-weight: 600;
            color: rgba(255, 255, 255, 1);
            overflow: visible !important;
        }

        .active::after {
            content: "";
            position: absolute;
            bottom: -9px;
            left: 50%;
            transform: translateX(-50%);
            width: 20px;
            height: 3px;
            background: rgba(255, 255, 255, 1);
            border-radius: 2px;
        }

        .item {
            position: relative;
            height: 200px;
            background: rgba(255, 255, 255, 1);
            box-shadow: 0px 5px 10px 0px rgba(15, 115, 174, 0.41);
            border-radius: 8px;
            margin: 15px;
            overflow: hidden;
        }

        .content {
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 60px;
            padding: 20px 15px 0 15px;
            background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.8) 100%);
        }

        .row {
            height: 20px;
        }

        .txt {
            font-size: 16px;
            font-weight: 500;
            color: rgba(255, 255, 255, 1);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .icon {
            width: 20px;
            height: 20px;
            min-width: 20px;
            margin-left: 25px;
        }

        .progress {
            min-width: fit-content;
            font-size: 14px;
            font-weight: 400;
            color: rgba(255, 255, 255, 1);
            text-align: right;
            margin-left: 25px;
        }

        .progress-outer {
            height: 4px;
            background: rgba(234, 247, 255, 1);
            border-radius: 2px;
            margin-top: 5px;
        }

        .progress-inner {
            height: 4px;
            background: rgba(90, 194, 255, 1);
            border-radius: 2px;
        }

        .off-on {
            position: absolute;
            left: 0;
            top: 0;
            right: 0;
            bottom: 0;
            margin: auto;
            width: 50px;
            height: 50px;
        }

        .books {
            padding: 0 7.5px;
            flex-wrap: wrap;
        }

        .book {
            width: 33.333%;
            padding: 0 7.5px;
        }

        .image {
            position: relative;
            width: 105px;
            height: 140px;
            margin: 15px auto 0 auto;
            background: rgba(77, 181, 216, 1);
            box-shadow: 0px 2px 9px 0px rgba(0, 0, 0, 0.16);
            border-radius: 5px;
            overflow: hidden;
        }

        .title {
            width: 105px;
            height: 32px;
            margin: 8px auto 0 auto;
            font-size: 14px;
            font-weight: 400;
            color: rgba(25, 25, 25, 1);
            line-height: 16px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
        }

        .collect {
            position: absolute;
            right: 5px;
            top: 5px;
            width: 20px;
            height: 20px;
        }
    </style>
</head>

<body>
    <div class="vueApp" v-cloak>
        <div class="navs" data-flex="cross:center">
            <div :class="navActive === 0 ? 'active nav' : 'nav'" @click="navActive = 0" data-flex-box="1"
                data-flex="main:center cross:center">观看历史</div>
            <div :class="navActive === 1 ? 'active nav' : 'nav'" @click="navActive = 1" data-flex-box="1"
                data-flex="main:center cross:center">收藏</div>
            <div :class="navActive === 2 ? 'active nav' : 'nav'" @click="navActive = 2" data-flex-box="1"
                data-flex="main:center cross:center">已购买</div>
        </div>
        <div class="books" data-flex>
            <div class="book" v-for="item in listData" @click="handleItem(item)">
                <div class="image">
                    <img :src="item.pic || item.goodsPic" alt="">
                    <div class="collect" v-show="navActive === 1" @click.stop="cancelCollect(item)">
                        <img src="../../image/ui/collect_2.png" alt="">
                    </div>
                </div>
                <div class="title">
                    {{ item.name || item.productName }}
                </div>
            </div>
        </div>
        <!-- <div v-show="navActive === 2">
            <div class="item" v-for="item,index in listData" @click="handleItem(item)">
                <div class="off-on">
                    <img src="../../image/ui/play.png" alt="">
                </div>
                <img :src="item.productPic" alt="">
                <div class="content">
                    <div class="row" data-flex="main:justify cross:center">
                        <div class="txt " data-flex-box="1 ">{{ item.productName }}</div>
                        <div class="progress ">{{ transformDate(item.termEnd) }}日前有效</div>
                    </div>
                </div>
            </div>
        </div> -->
        <div v-show="showTips" class="data-null">
            <p style="color: #000">暂时没有更多数据哦</p>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/service/service-tool.js"></script>
<script type="text/javascript" src="../../script/service/service-app.js"></script>
<script type="text/javascript" src="../../script/service/service-user.js"></script>
<script type="text/javascript" src="../../script/service/service-logic.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/vue.min.js"></script>
<script type="text/javascript">
    // html 的引号一律为双引号(""),js 为单引号('')
    var USER, $S, vm;
    var current;
    apiready = function () {
        $S = SERVICE();
        USER = USER();
        console.log(JSON.stringify(api.pageParam) + '=====pageParam');
        fnInit();
    };
    // 初始化
    function fnInit() {
        vm = new Vue({
            el: '.vueApp',
            data: {
                navActive: 0,
                pageNo: 1,
                pageSize: 10,
                listData: [],
                showTips: false
            },
            watch: {
                navActive: function () {
                    this.listData = [];
                    this.pageNo = 1;
                    load();
                }
            },
            methods: {
                transformDate: function (date) {
                    return formatTime(date, 'date');
                }
            }
        });
        load();
    }

    // 取消收藏
    function cancelCollect(item) {
        current = item;
        fnOpenAlert({
            alertType: 4,
            alertConfirmFn: 'alertConfirmFn'
        })
    }

    // 用户点击了弹窗的确认
    function alertConfirmFn() {
        var url = 'common/deleteById';
        var params = {
            'entityName': 'favoriteInfo',
            "id": current.id
        };
        var callback = function (data) {
            fnToast('取消成功');
            getPageData('headerRefreshing');
        };
        POST(url, params, callback);
    }

    function handleItem(item) {
        if(vm.navActive == 2) {
            var params = {
                id: item.goodsId
            };
            var callback = function(data) {
                if(data.errorStatus == 19999) {
                    fnToast(data.errorMessage);
                }else {
                    if(item.goodsId == data.videoId) {
                        // 套集
                    }else {
                        // 单集
                        item.videoId = item.goodsId +'';
                        item.goodsId = data.videoId;
                    }
                    fnOpenPublicWin('视频详情', 'video/detail', {
                        productsId: item.goodsId,
                        videoId: item.videoId,
                        isSlidBack: false
                    });
                }
            };
            POST('my/returnVideoId', params, callback)
        }else {
            fnOpenPublicWin('视频详情', 'video/detail', {
                productsId: item.bussTableId,
                isSlidBack: false
            });
        }
    }

    function load() {
        getPageData('headerRefreshing');
        fnAddHeaderRefreshingEvent(function () { //设置下拉刷新
            getPageData('headerRefreshing');
        });

        fnAddFooterLoadingEvent(function () { // 设置上拉加载
            getPageData('load');
        });
    }

    function getPageData(sign) {
        if (sign == 'headerRefreshing') {
            vm.pageNo = 1;
        } else {
            vm.pageNo++;
        }
        var url = '';
        var params = {};
        // 0: 历史记录 1: 收藏 2: 已购买
        if (vm.navActive == 0) {
            url = 'apiTrack/findTrackList';
            params = {
                "pageNo": vm.pageNo,
                "pageSize": vm.pageSize,
                'trackTypeCode': '02'
            }
        } else if (vm.navActive == 1) {
            url = 'apiFavorite/findFavoriteList';
            params = {
                "favoriteTypeCode": '02',
                "pageNo": vm.pageNo,
                "pageSize": vm.pageSize
            }
        } else if (vm.navActive == 2) {
            url = 'my/findVideoOrderList';
            params = {
                "pageNo": vm.pageNo,
                "pageSize": vm.pageSize
            };
        }
        var callback = function (data) {
            if (vm.pageNo == '1') {
                vm.listData = [];
            }
            var listData = data.listData;
            for (var i = 0; i < listData.length; i++) {
                var item = listData[i];
                item.lengthTime = tsDate(item.lengthTime);
            }
            api.refreshHeaderLoadDone();
            vm.listData = vm.listData.concat(data.listData);
            vm.$nextTick(function() {
                if(vm.listData.length === 0) {
                    vm.showTips = true;
                } else {
                    vm.showTips = false;
                }
            })
            // status 为200时,只返回data
        };
        POST(url, params, callback);
    }
</script>

</html>